import useLoading from '@/hooks/loading';
import { defineStore } from 'pinia';
import { reactive, toRefs } from 'vue';
import { getData } from './api';
export const useIndexStore = defineStore('index', () => {
  const { loading, setLoading } = useLoading(true);

  const state = reactive({
    order: [
      {
        value: [0],
        name: '待付款',
        itemStyle: {
          color: '#249EFF',
        },
      },
      {
        value: [0],
        name: '已付款',
        itemStyle: {
          color: '#846BCE',
        },
      },
      {
        value: [0],
        name: '已发货',
        itemStyle: {
          color: '#21CCFF',
        },
      },
      {
        value: [0],
        name: '已完成',
        itemStyle: {
          color: '#0E42D2',
        },
      },
      {
        value: [0],
        name: '已评价',
        itemStyle: {
          color: '#86DF6C',
        },
      },
      {
        value: [0],
        name: '已退款',
        itemStyle: {
          color: '#E5E6EB',
        },
      },
    ],
    teacher: [],
    student_ranking: [],
    squad_ranking: [],
    today_newStudent: 0,
    today_createOrder: 0,
    order_totalMoney: 0,
    person: [
      {
        value: [0],
        name: '教师',
        itemStyle: {
          color: '#249EFF',
        },
      },
      {
        value: [0],
        name: '学员',
        itemStyle: {
          color: '#21CCFF',
        },
      },
    ],
    rankingImage: [],
    TotalMoney: {
      label: ['今天', '本周', '本月', '今年'],
      value: [0, 0, 0, 0],
    },
    tide: {
      xAxis: [],
      goods: [],
      score: [],
    },
    order_totalMoney: 0,
    today_newOrder: 0,
    today_newRemark: 0,
    remark_yesterday: 0,
  });
  const fetchData = async () => {
    try {
      const { data } = await getData();
      Object.assign(state, data);
      console.log(data, loading);
      setLoading(false);
    } catch (error) {
      setLoading(false);
    }
  };
  fetchData();
  return {
    ...toRefs(state),
    loading,
    setLoading,
  };
});

export default useIndexStore;
